﻿<Window x:Class="StackHash.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:StackHash"
        xmlns:vcs="clr-namespace:StackHash.ValueConverters"
        Title="{Binding MainWindowTitle}" 
        Height="600" 
        Width="800" 
        Background="#ECEFFA"
        WindowStartupLocation="CenterScreen" 
        Icon="/StackHash;component/StackHash.ico" 
        MinWidth="600" 
        MinHeight="400"
        Name="mainWindow"
        Loaded="Window_Loaded" 
        Closed="Window_Closed">
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="MasterResources.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Menu Grid.Row="0" Background="#ECEFFA">
            <MenuItem Header="_File">
                <MenuItem Command="local:StackHashCommands.ExportCommand" IsEnabledChanged="MenuItem_IsEnabledChangedDimIcon">
                    <MenuItem.Icon>
                        <Image Source="Help\export.png" />
                    </MenuItem.Icon>
                    <MenuItem Command="local:StackHashCommands.ExportProductListCommand" />
                    <MenuItem Command="local:StackHashCommands.ExportEventListCommand" />
                    <MenuItem Command="local:StackHashCommands.ExportEventListFullCommand" />
                </MenuItem>
                <Separator />
                <MenuItem Command="local:StackHashCommands.UploadMappingCommand" ToolTip="Upload a new product mapping file to WinQual." IsEnabledChanged="MenuItem_IsEnabledChangedDimIcon" />
                <Separator />
                <MenuItem Command="local:StackHashCommands.ExitCommand" IsEnabledChanged="MenuItem_IsEnabledChangedDimIcon" />
            </MenuItem>
            <MenuItem Header="_Edit">
                <MenuItem Command="ApplicationCommands.Cut" IsEnabledChanged="MenuItem_IsEnabledChangedDimIcon" Name="menuItemCut">
                    <MenuItem.Icon>
                        <Image Source="Help\cut.png" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Command="ApplicationCommands.Copy" IsEnabledChanged="MenuItem_IsEnabledChangedDimIcon" Name="menuItemCopy">
                    <MenuItem.Icon>
                        <Image Source="Help\copy.png" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Command="ApplicationCommands.Paste" IsEnabledChanged="MenuItem_IsEnabledChangedDimIcon" Name="menuItemPaste">
                    <MenuItem.Icon>
                        <Image Source="Help\paste.png" />
                    </MenuItem.Icon>
                </MenuItem>
                <Separator />
                <MenuItem Command="ApplicationCommands.SelectAll" IsEnabledChanged="MenuItem_IsEnabledChangedDimIcon" Name="menuItemSelectAll" />
            </MenuItem>
            <MenuItem Header="_View">
                <MenuItem Command="NavigationCommands.BrowseBack" ToolTip="Return to the previous page." IsEnabledChanged="MenuItem_IsEnabledChangedDimIcon">
                    <MenuItem.Icon>
                        <Image Source="Help\back.png" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Command="NavigationCommands.BrowseHome" ToolTip="Go to the home page (mapped products)." IsEnabledChanged="MenuItem_IsEnabledChangedDimIcon">
                    <MenuItem.Icon>
                        <Image Source="Help\home.png" />
                    </MenuItem.Icon>
                </MenuItem>
                <Separator />
                <MenuItem Command="local:StackHashCommands.ShowDisabledProductsCommand" Name="menuItemShowDisabledProducts" ToolTip="Show products that are not currently synchronized with WinQual." IsEnabledChanged="MenuItem_IsEnabledChangedDimIcon" />
                <MenuItem Command="local:StackHashCommands.ShowEventsWithoutCabsCommand" Name="menuItemShowEventsWithoutCabs" ToolTip="Show events that do not have associated cab files." IsEnabledChanged="MenuItem_IsEnabledChangedDimIcon" />
                <Separator />
                <MenuItem Command="local:StackHashCommands.RefreshCommand" IsEnabledChanged="MenuItem_IsEnabledChangedDimIcon" />
            </MenuItem>
            <MenuItem Header="_Debug">
                <MenuItem Command="local:StackHashCommands.RunScriptCommand" ItemsSource="{Binding ScriptData}" IsEnabledChanged="MenuItem_IsEnabledChangedDimIcon">
                    <MenuItem.Icon>
                        <Image Source="Help\run-script.png" />
                    </MenuItem.Icon>
                    <MenuItem.ItemContainerStyle>
                        <Style TargetType="{x:Type MenuItem}">
                            <Setter Property="Command" Value="{x:Static local:StackHashCommands.RunScriptByNameCommand}" />
                            <Setter Property="CommandParameter" Value="{Binding Name}" />
                            <Setter Property="Header" Value="{Binding Name}" />
                        </Style>
                    </MenuItem.ItemContainerStyle>
                </MenuItem>
                <MenuItem Command="local:StackHashCommands.ScriptManagerCommand" ToolTip="Create, edit, remove and test debugger scripts." IsEnabledChanged="MenuItem_IsEnabledChangedDimIcon">
                    <MenuItem.Icon>
                        <Image Source="Help\script-manager.png" />
                    </MenuItem.Icon>
                </MenuItem>
                <Separator />
                <MenuItem Command="local:StackHashCommands.DebugCommand" ToolTip="Debug the contents of the selected Cab." IsEnabledChanged="MenuItem_IsEnabledChangedDimIcon">
                    <MenuItem.Icon>
                        <Image Source="Help\debug.png" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Command="local:StackHashCommands.DebugUsingCommand">
                    <MenuItem Command="local:StackHashCommands.DebugX86Command" />
                    <MenuItem Command="local:StackHashCommands.DebugX64Command" />
                    <MenuItem Command="local:StackHashCommands.DebugVisualStudioCommand" />
                </MenuItem>
                <Separator />
                <MenuItem Command="local:StackHashCommands.ExtractCabCommand" ToolTip="Extract the contents of the currently selected Cab to a local directory." IsEnabledChanged="MenuItem_IsEnabledChangedDimIcon">
                    <MenuItem.Icon>
                        <Image Source="Help\extract-cab.png" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Command="local:StackHashCommands.DownloadCabCommand" ToolTip="Download the currently selected cab." IsEnabledChanged="MenuItem_IsEnabledChangedDimIcon" />
                <MenuItem Command="local:StackHashCommands.OpenCabFolderCommand" ToolTip="Open the folder containing this cab file (only available if running on the same computer as the StackHash Service)." IsEnabledChanged="MenuItem_IsEnabledChangedDimIcon" />
            </MenuItem>
            <MenuItem Header="_Tools">
                <MenuItem Command="local:StackHashCommands.SyncCommand" ToolTip="Connects to WinQual and adds new information. This may take some time to complete." IsEnabledChanged="MenuItem_IsEnabledChangedDimIcon">
                    <MenuItem.Icon>
                        <Image Source="Help\synchronize.png" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Command="local:StackHashCommands.ResyncCommand" ToolTip="Connects to WinQual and refreshes all information. This may take some time to complete." IsEnabledChanged="MenuItem_IsEnabledChangedDimIcon">
                    <MenuItem.Icon>
                        <Image Source="Help\resync.png" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Command="local:StackHashCommands.CancelSyncCommand" ToolTip="Cancel the current WinQual synchronization." IsEnabledChanged="MenuItem_IsEnabledChangedDimIcon" />
                <MenuItem Command="local:StackHashCommands.SyncReportCommand" ToolTip="Shows the result of the most recent WinQual synchronization." IsEnabledChanged="MenuItem_IsEnabledChangedDimIcon" />
                <Separator />
                <MenuItem Command="local:StackHashCommands.SendAllToPluginsCommand" ToolTip="Send all profile data to one or more plugins. This may take some time to complete." IsEnabledChanged="MenuItem_IsEnabledChangedDimIcon" />
                <Separator />
                <MenuItem Command="local:StackHashCommands.BuildSearchCommand" ToolTip="Build a custom search" IsEnabledChanged="MenuItem_IsEnabledChangedDimIcon">
                    <MenuItem.Icon>
                        <Image Source="Help\search-builder.png" />
                    </MenuItem.Icon>
                </MenuItem>
                <Separator />
                <MenuItem Command="local:StackHashCommands.ServiceStatusCommand" ToolTip="Display diagnostic information from the StackHash service." IsEnabledChanged="MenuItem_IsEnabledChangedDimIcon" >
                    <MenuItem.Icon>
                        <Image Source="Help\service-status.png" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Command="local:StackHashCommands.ProfileManagerCommand" ToolTip="Configure profiles and settings for the StackHash Service." IsEnabledChanged="MenuItem_IsEnabledChangedDimIcon">
                    <MenuItem.Icon>
                        <Image Source="Help\service-options.png" />
                    </MenuItem.Icon>
                </MenuItem>
                <Separator />
                <MenuItem Command="local:StackHashCommands.OptionsCommand" ToolTip="Configure local settings for the StackHash Client." IsEnabledChanged="MenuItem_IsEnabledChangedDimIcon">
                    <MenuItem.Icon>
                        <Image Source="Help\client-options.png" />
                    </MenuItem.Icon>
                </MenuItem>
            </MenuItem>
            <MenuItem Header="_Help">
                <MenuItem Command="Help" Header="StackHash _Help" IsEnabledChanged="MenuItem_IsEnabledChangedDimIcon">
                    <MenuItem.Icon>
                        <Image Source="Help\help.png" />
                    </MenuItem.Icon>
                </MenuItem>
                <Separator />
                <MenuItem Command="local:StackHashCommands.AboutCommand" IsEnabledChanged="MenuItem_IsEnabledChangedDimIcon">
                    <MenuItem.Icon>
                        <Image Source="Help\stackhash_16.png" />
                    </MenuItem.Icon>
                </MenuItem>
            </MenuItem>
        </Menu>
        <ToolBarTray Grid.Row="1" Background="#ECEFFA">
            <ToolBar Band="1" BandIndex="1" KeyboardNavigation.TabNavigation="Continue" Name="toolBarMain">
                <ToolBar.Background>
                    <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                        <GradientStop Color="#FAFAFD" Offset="0.0" />
                        <GradientStop Color="#C4CBDB" Offset="1.0" />
                    </LinearGradientBrush>
                </ToolBar.Background>
                <Button Command="NavigationCommands.BrowseBack" ToolTip="Return to the previous page.">
                    <Image Source="Help\back.png" Style="{StaticResource ButtonImageStyle}" />
                </Button>
                <Button Command="NavigationCommands.BrowseHome" ToolTip="Go to the home page (mapped products).">
                    <Image Source="Help\home.png" Style="{StaticResource ButtonImageStyle}" />
                </Button>
                <Separator />
                <Button Command="ApplicationCommands.Cut" Name="toolbarButtonCut">
                    <Image Source="Help\cut.png" Style="{StaticResource ButtonImageStyle}" />
                </Button>
                <Button Command="ApplicationCommands.Copy" Name="toolbarButtonCopy">
                    <Image Source="Help\copy.png" Style="{StaticResource ButtonImageStyle}" />
                </Button>
                <Button Command="ApplicationCommands.Paste" Name="toolbarButtonPaste">
                    <Image Source="Help\paste.png" Style="{StaticResource ButtonImageStyle}" />
                </Button>
                <Separator />
                <Button Command="local:StackHashCommands.ScriptManagerCommand" ToolTip="Create, edit, remove and test debugger scripts.">
                    <Image Source="Help\script-manager.png" Style="{StaticResource ButtonImageStyle}" />
                </Button>
                <Button Command="local:StackHashCommands.DebugCommand" ToolTip="Debug the contents of the selected Cab.">
                    <Image Source="Help\debug.png" Style="{StaticResource ButtonImageStyle}" />
                </Button>
            </ToolBar>
            <ToolBar Band="1" BandIndex="2" KeyboardNavigation.TabNavigation="Continue" Name="toolBarSearch">
                <ToolBar.Background>
                    <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                        <GradientStop Color="#FAFAFD" Offset="0.0" />
                        <GradientStop Color="#C4CBDB" Offset="1.0" />
                    </LinearGradientBrush>
                </ToolBar.Background>
                <Label IsEnabled="{Binding NotBusy}" Target="{Binding ElementName=comboBoxSearch}" VerticalAlignment="Center">_Search:</Label>
                <ComboBox Name="comboBoxSearch" ItemsSource="{Binding SearchList}" Width="250" IsEditable="True" KeyDown="comboBoxSearch_KeyDown" DropDownClosed="comboBoxSearch_DropDownClosed">
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding}">
                                <TextBlock.ContextMenu>
                                    <ContextMenu>
                                        <MenuItem Name="searchListRemove" Header="_Remove" Click="searchListRemove_Click">
                                            <MenuItem.Icon>
                                                <Image Source="Help\clear-search.png" />
                                            </MenuItem.Icon>
                                        </MenuItem>
                                    </ContextMenu>
                                </TextBlock.ContextMenu>
                            </TextBlock>
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>
                <Button Command="local:StackHashCommands.SearchCommand" VerticalAlignment="Center" ToolTip="Start search">
                    <Image Source="Help\search.png" Style="{StaticResource ButtonImageStyle}" />
                </Button>
                <Button Command="local:StackHashCommands.ClearSearchCommand" VerticalAlignment="Center" ToolTip="Clear current search">
                    <Image Source="Help\clear-search.png" Style="{StaticResource ButtonImageStyle}" />
                </Button>
                <Button Command="local:StackHashCommands.BuildSearchCommand" VerticalAlignment="Center" ToolTip="Build a custom search">
                    <Image Source="Help\search-builder.png" Style="{StaticResource ButtonImageStyle}" />
                </Button>
            </ToolBar>
            <ToolBar Band="1" BandIndex="3" KeyboardNavigation.TabNavigation="Continue" Name="toolBarTools">
                <ToolBar.Background>
                    <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                        <GradientStop Color="#FAFAFD" Offset="0.0" />
                        <GradientStop Color="#C4CBDB" Offset="1.0" />
                    </LinearGradientBrush>
                </ToolBar.Background>
                <Button Command="local:StackHashCommands.SyncCommand" ToolTip="Connects to WinQual and adds new information. This may take some time to complete.">
                    <Image Source="Help\synchronize.png" Style="{StaticResource ButtonImageStyle}" />
                </Button>
                <Button Command="local:StackHashCommands.ProfileManagerCommand" ToolTip="Configure profiles and settings for the StackHash Service.">
                    <Image Source="Help\service-options.png" Style="{StaticResource ButtonImageStyle}" />
                </Button>
                <Button Command="local:StackHashCommands.OptionsCommand" ToolTip="Configure local settings for the StackHash Client.">
                    <Image Source="Help\client-options.png" Style="{StaticResource ButtonImageStyle}" />
                </Button>
                <Label IsEnabled="{Binding NotBusy}" Target="{Binding ElementName=comboBoxProfile}" VerticalAlignment="Center">_Profile:</Label>
                <ComboBox Name="comboBoxProfile" ItemsSource="{Binding ActiveContextCollection}" SelectedItem="{Binding CurrentContext, Mode=TwoWay}" DisplayMemberPath="ProfileName" Width="150" VerticalAlignment="Stretch" Margin="0,2" IsEnabled="{Binding NotBusy}" SelectionChanged="comboBoxProfile_SelectionChanged" />
            </ToolBar>
        </ToolBarTray>
        <local:MainProductList x:Name="viewMainProductList" FocusManager.IsFocusScope="True" Grid.Row="2" SearchRequest="HandleSearchRequest" SearchOrPopulateEvents="viewMainProductList_SearchOrPopulateEvents" ShowDisabledProducts="viewMainProductList_ShowDisabledProducts"  Visibility="{Binding Path=CurrentView, Converter={StaticResource productListConverter}}" PreviewMouseDown="View_PreviewMouseDown" />
        <local:EventList x:Name="viewEventList" FocusManager.IsFocusScope="True" Grid.Row="2" SearchRequest="HandleSearchRequest" Visibility="{Binding Path=CurrentView, Converter={StaticResource eventListConverter}}" PreviewMouseDown="View_PreviewMouseDown" />
        <local:EventDetails x:Name="viewEventDetails" FocusManager.IsFocusScope="True" Grid.Row="2" Visibility="{Binding Path=CurrentView, Converter={StaticResource eventDetailsConverter}}" PreviewMouseDown="View_PreviewMouseDown" />
        <local:CabDetails x:Name="viewCabDetails" FocusManager.IsFocusScope="True" Grid.Row="2" Visibility="{Binding Path=CurrentView, Converter={StaticResource cabDetailsConverter}}" PreviewMouseDown="View_PreviewMouseDown" />
        <StatusBar Grid.Row="3">
            <StatusBarItem DockPanel.Dock="Right" Visibility="{Binding Path=ServiceProgressVisible, Converter={StaticResource trueVisibleConverter}}">
                <ProgressBar Minimum="0" Maximum="100" Value="{Binding ServiceProgress, Mode=OneWay}" Margin="3,0,3,0" Width="100px" Height="15px" HorizontalAlignment="Center" />
            </StatusBarItem>
            <StatusBarItem DockPanel.Dock="Right">
                <TextBlock Margin="0,0,10,0" VerticalAlignment="Center" Text="{Binding ServiceStatusText}" />
            </StatusBarItem>
            <StatusBarItem Visibility="{Binding PluginHasError, Converter={StaticResource trueNotCollapsedConverter}}" DockPanel.Dock="Right">
                <TextBlock VerticalAlignment="Center" Margin="3,0,3,0">
                    <TextBlock Foreground="Red" FontWeight="Bold">!</TextBlock>
                    <TextBlock><Hyperlink Name="hyperlinkPluginFailure" Click="hyperlinkPluginFailure_Click">Plugin Failure</Hyperlink></TextBlock>
                </TextBlock>
            </StatusBarItem>
            <StatusBarItem Name="statusBarItemSyncFailed" DockPanel.Dock="Right">
                <TextBlock VerticalAlignment="Center" Margin="3,0,3,0">
                    <TextBlock Foreground="Red" FontWeight="Bold">!</TextBlock>
                    <TextBlock>Synchronization Failed:</TextBlock> 
                    <TextBlock><Hyperlink Command="local:StackHashCommands.SyncReportCommand">View Report</Hyperlink></TextBlock>
                </TextBlock>
            </StatusBarItem>
            <StatusBarItem Name="statusBarItemSyncSucceeded" DockPanel.Dock="Right">
                <TextBlock VerticalAlignment="Center" Margin="3,0,3,0">
                    <TextBlock>Synchronization Succeeded:</TextBlock> 
                    <TextBlock><Hyperlink Command="local:StackHashCommands.SyncReportCommand">View Report</Hyperlink></TextBlock>
                </TextBlock>
            </StatusBarItem>
            <StatusBarItem DockPanel.Dock="Left">
                <Ellipse Margin="3,0,0,0" Width="15px" Height="15px" Stroke="DarkGray" VerticalAlignment="Center" Name="ellipseBusy">
                    <Ellipse.Fill>
                        <RadialGradientBrush GradientOrigin="0.75, 0.25">
                            <GradientStop x:Name="StopEllipse1" Color="Green" Offset="0.0" />
                            <GradientStop x:Name="StopEllipse2" Color="LightGreen" Offset="1.0" />
                        </RadialGradientBrush>
                    </Ellipse.Fill>
                    <Ellipse.RenderTransform>
                        <RotateTransform CenterX="7.5" CenterY="7.5" Angle="0" x:Name="EllipseTransform" />
                    </Ellipse.RenderTransform>
                    <Ellipse.Resources>
                        <Storyboard x:Key="StoryboardEllipse">
                            <DoubleAnimation x:Name="RotateEllipse" Storyboard.TargetName="EllipseTransform" Storyboard.TargetProperty="Angle" By="360" BeginTime="0:0:2" Duration="0:0:3" AutoReverse="False" RepeatBehavior="Forever" />
                            <ColorAnimation x:Name="FadeStop1" Storyboard.TargetName="StopEllipse1" Storyboard.TargetProperty="Color" To="LightYellow" Duration="0:0:2" />
                            <ColorAnimation x:Name="FadeStop2" Storyboard.TargetName="StopEllipse2" Storyboard.TargetProperty="Color" To="Orange" Duration="0:0:1" />
                            <ColorAnimation x:Name="FadeStop2Timeout" Storyboard.TargetName="StopEllipse2" Storyboard.TargetProperty="Color" To="Red" BeginTime="0:1:0" Duration="0:14:0" />
                        </Storyboard>
                    </Ellipse.Resources>
                </Ellipse>
            </StatusBarItem>
            <StatusBarItem DockPanel.Dock="Left">
                <TextBlock Margin="0,0,0,0" VerticalAlignment="Center" Text="{Binding StatusText}" />
            </StatusBarItem>
        </StatusBar>
    </Grid>
</Window>
